from ..async_tcp_server import serverInQueue, serverOutQueue
import asyncio


class OledControl:

    def __init__(self):
        self.__inputText: str = ''

    def getInputText(self):
        return self.__inputText

    def setInputText(self, input: str):
        self.__inputText = input

    async def clearInputText(self):
        self.__inputText = ' '
        cmd = self.__changeCMD()
        await self.__sendCMD(cmd)

    async def submitInputText(self):
        cmd = self.__changeCMD()
        await self.__sendCMD(cmd)

    def __changeCMD(self):
        return f"O={self.__inputText};"

    async def __sendCMD(self, cmd):
        serverInQueue.put(cmd)
        res_status = "F"
        while res_status != 'T':
            if not serverOutQueue.empty():
                res_status = serverOutQueue.get()
            else:
                await asyncio.sleep(0)
